package com.freda.oa.flow.run.model.impl;

import com.freda.oa.flow.run.model.itf.FlowInstanceModelItf;
import com.freda.oa.flow.run.vo.FlowRunInfoVo;
import com.freda.oa.flow.utl.FlowIdHelper;

/**
 * 操作instance
 * @author Rally
 *
 */
public class FlowInstanceModelImpl extends FlowBaseModelImpl implements FlowInstanceModelItf{
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowInstanceModelItf#addInstance(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int addInstance(FlowRunInfoVo runInfo)
	{
		
		String instanceId = FlowIdHelper.getInstanceId();
		
		runInfo.setInstanceId(instanceId);
		
		runInfo.setsId(runInfo.getDeployCtlKey()+ "." + instanceId);
		
		g4Dao.insert("FlowInstance.add", runInfo);
		
		return 1;
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowInstanceModelItf#editInstance(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int editInstance(FlowRunInfoVo runInfo)
	{
		if(g4Dao.update("FlowInstance.update", runInfo) != -1)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowInstanceModelItf#editState(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int editState(FlowRunInfoVo runInfo)
	{
		
		if(g4Dao.update("FlowInstance.updateState", runInfo) != -1)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowInstanceModelItf#endInstance(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int endInstance(FlowRunInfoVo runInfo)
	{
		
		if(g4Dao.update("FlowInstance.updateEndState", runInfo) != -1)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}

}
